package com.canaan.business.controller.pc.storehouse;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.business.domain.storehouse.StockCheckResult;
import com.canaan.business.service.storehouse.IStockCheckResultService;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * 库存盘点结果Controller
 *
 * @author ruoyi
 * @date 2023-02-16
 */
@Api(tags = "库存盘点结果")
@RestController
@RequestMapping("/storehouse/checkResult")
public class StockCheckResultController extends BaseController {
    @Resource
    private IStockCheckResultService stockCheckResultService;

    /**
     * 查询库存盘点结果列表
     */
    @ApiOperation(value = "查询库存盘点结果列表")
    @GetMapping("/list")
    public TableDataInfo list(StockCheckResult stockCheckResult) {
        startPage();
        List<StockCheckResult> list = stockCheckResultService.selectStockCheckResultList(stockCheckResult);
        return getDataTable(list);
    }

    /**
     * 导出库存盘点结果列表
     */
    @ApiOperation(value = "导出库存盘点结果列表")
    @Log(title = "库存盘点结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockCheckResult stockCheckResult) {
        List<StockCheckResult> list = stockCheckResultService.selectStockCheckResultList(stockCheckResult);
        ExcelUtil<StockCheckResult> util = new ExcelUtil<StockCheckResult>(StockCheckResult.class);
        util.exportExcel(response, list, "库存盘点结果数据");
    }

    /**
     * 获取库存盘点结果详细信息
     */
    @ApiOperation(value = "获取库存盘点结果详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(stockCheckResultService.selectStockCheckResultById(id));
    }

    /**
     * 新增库存盘点结果
     */
    @ApiOperation(value = "新增库存盘点结果")
    @Log(title = "库存盘点结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockCheckResult stockCheckResult) {
        return toAjax(stockCheckResultService.insertStockCheckResult(stockCheckResult));
    }

    /**
     * 修改库存盘点结果
     */
    @ApiOperation(value = "修改库存盘点结果")
    @Log(title = "库存盘点结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockCheckResult stockCheckResult) {
        return toAjax(stockCheckResultService.updateStockCheckResult(stockCheckResult));
    }

    /**
     * 删除库存盘点结果
     */
    @ApiOperation(value = "删除库存盘点结果")
    @Log(title = "库存盘点结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(stockCheckResultService.deleteStockCheckResultByIds(ids));
    }


    /**
     * 批量新增库存盘点结果
     */
    @ApiOperation(value = "批量新增库存盘点结果")
    @Log(title = "批量新增库存盘点结果", businessType = BusinessType.INSERT)
    @PostMapping("/batchAdd")
    public AjaxResult batchAdd(@RequestParam("checkDetailNo")String checkDetailNo,@RequestBody List<StockCheckResult> stockCheckResults) {
        return toAjax(stockCheckResultService.batchAdd(checkDetailNo,stockCheckResults));
    }
}
